//
//  FMDBSQLManager.swift
//  FMDB-Swift
//
//  Created by Jacky Sun on 16/6/13.
//  Copyright © 2016年 syf. All rights reserved.
//

import UIKit

class FMDBSQLManager: NSObject {

    private static let manager = FMDBSQLManager()
    
    //MARK: - 单例
    class func shareSingleManager() ->FMDBSQLManager{
        
        return manager
    }
    
    /// 数据库队列
    var dbQueue: FMDatabaseQueue?
    
    /**
     开通数据库
     
     - parameter path: <#path description#>
     */
    func opendb(path: String){
        let filePath = (NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last! as NSString).stringByAppendingPathComponent(path)
        
        print(filePath)
     
        // 初始化数据库对象
        // 如果用FMDatabaseQueue创建数据库对象，就不用打开数据库了
        dbQueue = FMDatabaseQueue(path: filePath)
        
        // 创表
         createTable()
    }
    
    
    func createTable(){
        let sql = "create table if not exists s_investor(statusId INTEGER PRIMARY KEY, statusText text, userId text);"
        
        dbQueue!.inDatabase { (db) in
            if db.executeUpdate(sql, withArgumentsInArray: nil){
                print("创建表成功！！！")
            }
        }
    }
    
}
